package it.infodea.tapestrydea.services;

import java.io.IOException;
import java.util.Properties;

import org.apache.tapestry5.Asset;
import org.apache.tapestry5.ioc.services.SymbolProvider;
import org.slf4j.Logger;

public class PropertiesSymbolProvider implements SymbolProvider {

	private Properties properties;
	
	public PropertiesSymbolProvider(Properties properties) {
		super();
		this.properties = properties != null ? properties : new Properties();
	}

	public PropertiesSymbolProvider(Asset assetProperties, Logger logger) {
		this(new Properties());
		try {
			properties.load(assetProperties.getResource().openStream());
		} catch (IOException e) {
			logger.error("Impossibile aprire lo stream della risorsa " + assetProperties.getResource(), e);
		}
	}
	
	public String valueForSymbol(String symbolName) {
		return properties.getProperty(symbolName);
	}

}
